﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;


namespace WindowsFormsApplication1
{
    public partial class mytask : Form
    {
        private string staffid = "";
        private string staffname = "";
        dbutils db = new dbutils();
        public mytask()
        {
            InitializeComponent();
        }
        public void set_value(string staffid, string staffname)
        {
            this.staffid = staffid;
            this.staffname = staffname;
        }

        private void mytask_Load(object sender, EventArgs e)
        {
            load_data();
        }
        private void load_data()
        {
            string connection;
            string query;
            DataSet myds;
            connection = dbutils.constr;
            query = "select * from task where staffid='"+staffid+"' order by release_date DESC";
            MySqlConnection conn = new MySqlConnection(connection);
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            conn.Open();
            adapter.SelectCommand = new MySqlCommand(query, conn);
            myds = new DataSet();
            adapter.Fill(myds, "Bill");
            bindingSource1.DataSource = myds.Tables["Bill"];
            dataGridView1.DataSource = bindingSource1;
            dataGridView1.Columns["num"].HeaderText = "任务编号";
            dataGridView1.Columns["staffid"].HeaderText = "员工编号";
            dataGridView1.Columns["staffname"].HeaderText = "员工姓名";
            dataGridView1.Columns["release_date"].HeaderText = "发布日期";
            dataGridView1.Columns["release_text"].HeaderText = "任务说明";
            dataGridView1.Columns["state"].HeaderText = "任务状态";
            conn.Close();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == null)
                return;
            if (textBox1.Text.Trim() == "")
                return;
            string num = textBox1.Text.Trim();
            if (MessageBox.Show("确定提交任务 " + num + " 吗？", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                return;
            string sql = "update task set state='已完成' where staffid='"+staffid+"' and num="+num+"";
            if (db.insert(sql) == 0)
            {
                MessageBox.Show("error!");
                return;
            }
            MessageBox.Show("操作成功！");
            load_data();
        }
    }
}
